#include "logindialog.h"

#include <QDebug>
#include <QLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>

LoginDialog::LoginDialog(QWidget *parent) :
    QDialog(parent)
{
    setObjectName("loginDialog");

    setupUi();
}

void LoginDialog::setupUi(void)
{
    //垂直布局
    QVBoxLayout *mainVLayout = new QVBoxLayout();
    mainVLayout->setContentsMargins(15, 15, 15, 15);

    QWidget * widget = new QWidget();
    QHBoxLayout *iconHLayout = new QHBoxLayout();
    iconHLayout->setContentsMargins(0, 0, 0, 0);
    QLabel * loginLabel = new QLabel();
    loginLabel->setObjectName("loginLabel");
    loginLabel->setFixedSize(200, 200);
    loginLabel->setPixmap(QPixmap(":/image/login.png"));
    loginLabel->setAlignment(Qt::AlignCenter);
    //图片按照控件自动调整
    loginLabel->setScaledContents(true);
    iconHLayout->addWidget(loginLabel);
    widget->setLayout(iconHLayout);
    mainVLayout->addWidget(widget);
    mainVLayout->addStretch(2);

    //水平布局
    QHBoxLayout *userHLayout = new QHBoxLayout();
    userHLayout->setContentsMargins(0, 0, 0, 0);
    QLabel * userLabel = new QLabel("用户：");
    userLabel->setObjectName("userLabel");
    userLabel->setFixedHeight(25);
    m_userLineEdit = new QLineEdit();
    m_userLineEdit->setObjectName("userLineEdit");
    m_userLineEdit->setFixedHeight(25);
    userHLayout->addWidget(userLabel);
    userHLayout->addWidget(m_userLineEdit);
    mainVLayout->addLayout(userHLayout);

    QHBoxLayout *pwdHLayout = new QHBoxLayout();
    pwdHLayout->setContentsMargins(0, 0, 0, 0);
    QLabel * pwdLabel = new QLabel("密码：");
    pwdLabel->setObjectName("pwdLabel");
    pwdLabel->setFixedHeight(25);
    m_pwdLineEdit = new QLineEdit();
    m_pwdLineEdit->setObjectName("pwdLineEdit");
    m_pwdLineEdit->setFixedHeight(25);
    m_pwdLineEdit->setEchoMode(QLineEdit::Password);
    pwdHLayout->addWidget(pwdLabel);
    pwdHLayout->addWidget(m_pwdLineEdit);
    mainVLayout->addLayout(pwdHLayout);

    QHBoxLayout *foregetHLayout = new QHBoxLayout();
    foregetHLayout->setContentsMargins(0, 0, 0, 0);
    foregetHLayout->addStretch(1);
    QLabel * foregetLabel = new QLabel("忘记密码？");
    foregetLabel->setObjectName("foregetLabel");
    foregetLabel->setFixedHeight(25);
    foregetHLayout->addWidget(foregetLabel);
    mainVLayout->addLayout(foregetHLayout);
    mainVLayout->addStretch(2);

    QHBoxLayout *btnHLayout = new QHBoxLayout();
    btnHLayout->setContentsMargins(0, 0, 0, 0);
    QPushButton * loginBtn = new QPushButton("登录");
    loginBtn->setObjectName("loginBtn");
    loginBtn->setFixedHeight(35);
    //connect(loginBtn, &QPushButton::clicked, this, &LoginDialog::loginBtnClicked);

    QPushButton * registerBtn = new QPushButton("注册");
    registerBtn->setObjectName("registerBtn");
    registerBtn->setFixedHeight(35);
    connect(registerBtn, &QPushButton::clicked, this, &LoginDialog::signSwitchRegister);

    btnHLayout->addStretch(1);
    btnHLayout->addWidget(loginBtn);
    btnHLayout->addStretch(1);
    btnHLayout->addWidget(registerBtn);
    btnHLayout->addStretch(1);
    mainVLayout->addLayout(btnHLayout);
    mainVLayout->addStretch(2);

    this->setLayout(mainVLayout);
}
